package com.codeduck.controller;

//import com.codeduck.config.DataSourceConfig;
import com.codeduck.HealthCommonVar;
import com.codeduck.service.HealthCheckService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.naming.NamingException;
import java.util.Map;

/**
 * @author: <a href="mailto:codeduck@163.com">codeduck</a>
 * @date: 2023/01/03
 */
@RestController
@RequestMapping("check")
public class IndexController {

    @Resource
    private HealthCheckService healthCheckService;

    @RequestMapping("/test")
    public String test() {
        return "test";
    }

    @RequestMapping("/health/1")
    public String check01() {
        String rs = "@@health@@";
        if (!HealthCommonVar.getDbSafe().equals("health")) {
            rs = "数据库连接异常！";
        }

        if (!HealthCommonVar.getFsSafe().equals("health")) {
            rs = rs + "磁盘异常!";
        }
        return rs;
    }

    @RequestMapping("/health/2")
    public String check02() {
        String rs = "@@health@@";
        if (healthCheckService.dbCheck() != 0) {
            rs = "数据库连接异常！";
        }

        if (healthCheckService.fsCheck() != 0) {
            rs = rs + "磁盘异常!";
        }
        return rs;
    }

}
